package com.hotel.controller;

import com.hotel.common.AjaxResult;
import com.hotel.domain.service.RoomTypeService;
import com.hotel.pojo.RoomType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/roomType")
public class RoomTypeController {

    @Autowired
    private RoomTypeService roomTypeService;

    /**
     * 分页查询房间类型
     * @param roomType 房间类型对象
     * @param page 页码
     * @param perPage 每一页的条数
     * @return AjaxResult
     */
    @GetMapping("/{page}/{perPage}")
    @ResponseBody
    public AjaxResult getRoomTypeList(RoomType roomType, @PathVariable("page") int page, @PathVariable("perPage") int perPage){
        return AjaxResult.queryAjax(roomTypeService.getRoomTypeList(roomType, page, perPage));
    }

    /**
     * 获得所有房间类型
     * @return AjaxResult
     */
    @GetMapping("/getAll")
    @ResponseBody
    public AjaxResult getAllRoomType(){
        return AjaxResult.queryAjax(roomTypeService.getAllRoomType());
    }

    /**
     * 新增房间类型
     * @param roomType 房间类型对象
     * @return AjaxResult
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addRoomType(@RequestBody RoomType roomType){
        return AjaxResult.updateAjax(roomTypeService.addRoomType(roomType));
    }

    /**
     * 更新房间类型
     * @param roomType 房间类型对象
     * @return AjaxResult
     */
    @PostMapping("/update")
    @ResponseBody
    public AjaxResult updateRoomType(@RequestBody RoomType roomType){
        return AjaxResult.updateAjax(roomTypeService.updateRoomType(roomType));
    }

    /**
     * 逻辑删除房间类型
     * @param roomTypeId 房间类型ID
     * @return AjaxResult
     */
    @PostMapping("/delete")
    @ResponseBody
    public AjaxResult deleteRoomType(@RequestBody int roomTypeId){
        RoomType roomType = new RoomType();
        roomType.setRoomTypeDel(1);
        roomType.setRoomTypeId(roomTypeId);
        return AjaxResult.updateAjax(roomTypeService.updateRoomType(roomType));
    }

}
